<?php
/**
 *
 * Helper to build an alphabet with action links.
 *
 * @category Lux
 *
 * @package Lux_View
 *
 * @author Rodrigo Moraes <rodrigo.moraes@gmail.com>
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 * @version $Id: ActionListAlphabet.php 137 2008-09-29 17:47:03Z rodrigo.moraes $
 *
 */
class Lux_View_Helper_ActionListAlphabet extends Lux_View_Helper_ActionList
{
    /**
     *
     * Builds an alphabet with action links.
     *
     * @param string $uri Uri for items action links, formatted using sprintf().
     *
     * @param string $current The currently "active" item in the list, if any.
     *
     * @param array $config Additional config options to build the list.
     *
     * @param array $pre Optional items for the beginning of the list.
     *
     * @param array $post Optional items for the end of the list.
     *
     * @return string The list of action items.
     *
     */
    public function actionListAlphabet($uri, $current = null, $config = null,
        $pre = null, $post = null)
    {
        // start the list with $pre items
        $items = (array) $pre;
        
        // build the alphabet
        $list = range('a', 'z');
        
        // set action info for each letter.
        foreach($list as $letter) {
            $items[$letter] = array(sprintf($uri, $letter), $letter);
        }
        
        // add $post items to the end of the list
        $items = array_merge($items, (array) $post);
        
        // done
        return $this->actionList($items, $current, $config);
    }
}
